package com.example.module_hp_zao_yin.fragment;

import android.Manifest;
import android.os.Bundle;
import android.view.View;
import androidx.fragment.app.FragmentActivity;
import androidx.lifecycle.Observer;
import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.example.module_hp_zao_yin.BR;
import com.example.module_hp_zao_yin.R;
import com.example.module_hp_zao_yin.activity.HpGongJuSoundActivity;
import com.example.module_hp_zao_yin.base.BaseMvvmFragment;
import com.example.module_hp_zao_yin.base.BaseViewModel;
import com.example.module_hp_zao_yin.databinding.FragmentHpGongJuMainBinding;
import com.fwlst.lib_base.utils.AdUtils;
import com.fwlst.lib_base.utils.JtXXPermissions;
import java.util.ArrayList;
import java.util.List;

import kotlin.Unit;
import kotlin.jvm.functions.Function0;

@Route(path = "/hpZaoYin/route/HpGongJuMainFragment")
public class HpGongJuMainFragment extends BaseMvvmFragment<FragmentHpGongJuMainBinding, BaseViewModel> {
    @Override
    protected int initLayout() {
        return R.layout.fragment_hp_gong_ju_main;
    }

    @Override
    protected int initBR() {
        return BR.data;
    }

    @Override
    protected void initView(View view, Bundle savedInstanceState) {
        //banner广告
        AdUtils.INSTANCE.loadBannerAd(mContext,binding.bannerContainer);
        viewModel.getCurrentType().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                if(integer==0) return;
                if(integer==1||integer==2){
                    List<String> pre = new ArrayList<>();
                    pre.add(Manifest.permission.RECORD_AUDIO);
                    JtXXPermissions.INSTANCE.requestPermission((FragmentActivity) mContext, "", pre, new Function0<Unit>() {
                        @Override
                        public Unit invoke() {
                            if(integer==1){
                                ARouter.getInstance().build("/hpZaoYinMedia/route/HpZaoYinPhotoActivity").navigation();
                            }else if(integer==2){
                                ARouter.getInstance().build("/hpZaoYinMedia/route/HpZaoYinVideoActivity").navigation();
                            }
                            return null;
                        }
                    });

                }else {
               AdUtils.INSTANCE.checkFunction(requireContext(), new Function0<Unit>() {
                   @Override
                   public Unit invoke() {
                       switch (integer){
                           case 3:
                               navigateTo(HpGongJuSoundActivity.class);
                               break;
                           case 4:
                               ARouter.getInstance().build("/hpWhiteNoise/route/HpSleepFocusActivity").navigation();
                               break;
                           case 5:
                               ARouter.getInstance().build("/hpWhiteNoise/route/HpSleepBreatheActivity").navigation();
                               break;
                           case 6:
                               ARouter.getInstance().build("/hpWhiteNoise/route/HpSleepPlayActivity").navigation();
                               break;
                           case 7:
                               ARouter.getInstance().build("/hpWhiteNoise/route/HpSleepMonitorActivity").navigation();
                               break;
                       }
                       return null;
                   }
               });
                }

            }
        });
    }
    @Override
    public void onDestroy() {
        super.onDestroy();
        AdUtils.INSTANCE.destroyBannerAd();
    }
}